package cn.thoughtworks.school.repositories;

import cn.thoughtworks.school.entities.SubjectiveQuiz;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface SubjectiveQuizRepository extends JpaRepository<SubjectiveQuiz, Long>,JpaSpecificationExecutor<SubjectiveQuiz> {
    Optional<SubjectiveQuiz> findByIdAndIsAvailableIsTrue(Long id);

    List<SubjectiveQuiz> findAllByIsAvailableIsTrueAndIdIn(List<Long> ids);

    @Query(value = "SELECT  b FROM SubjectiveQuiz b JOIN b.tags t WHERE  b.isAvailable=true AND t.name in :tags")
    List<SubjectiveQuiz> findSubjectivesByTags(@Param("tags") List<String> tags);

    List<SubjectiveQuiz> findByIdIn(List<Long> ids);

}
